Repository navigation
Show the questionnaire's conditional flow in a Flow panel - #16
Draft
PSchmiedmayer wants to merge 2 commits into
Draft
PSchmiedmayer wants to merge 2 commits into
PSchmiedmayer wants to merge 2 commits into
Conversation
The side panel gets a Flow tab that lists every item in document order with its enableWhen conditions and draws an edge from each referenced question to the condition. It marks conditions on missing or later items, reflects validation findings on edges, and marks items that no answers can enable. Rows form an accessible tree that shares the selection with the outline and the inspector. The layout, including lane assignment and reachability, is computed by layoutFlow in anvil-core. The preview's enablement helpers now skip imported values that are not arrays or objects, which the layout reuses.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
♻️ Current situation & Problem
Authors set
enableWhenconditions one item at a time in the inspector.Nothing shows how the conditions of a whole questionnaire fit together: which questions decide which items, whether a condition refers to a question that comes later, or whether an item can be shown at all.
Validation reports a condition on a missing linkId, but an item that depends on that item, a cycle of conditions, or a group that depends on one of its own children goes unnoticed until someone tries the preview with the right answers.
⚙️ Release Notes
The side panel has a new Flow tab, opened from the toolbar next to Preview and JSON.
It lists every item in document order, indented like the outline, with its conditions below it, and draws an edge from each referenced question to the condition.
Conditions read as
when smoke = Yes (yes)followed byandororfor further conditions, depending onenableBehavior.Coded answers use the display of the referenced question's answer option.
Findings show on the rows and edges:
Selection is shared with the outline and the inspector.
Clicking an item row selects the item, clicking a condition row selects the item that has the condition, and clicking the question of a condition selects that question.
The edges of the selected item are drawn in the accent color.
The layout is computed in
anvil-corebylayoutFlow(document), a pure function, andanvil-reactrenders it with fixed row heights and one SVG for the edges:The layout keeps document order, because the order is what authors need to judge, and a layered graph layout would reorder items to reduce crossings.
Edges run in lanes to the left of the rows, which is the layout of an arc diagram.
Lanes are assigned greedily with the shortest edges innermost, so edges that share rows never overlap, and edges leaving one question in the same direction can share a lane.
This needs no layout library.
Reachability starts from the items the preview enables with the initial answers and adds every item whose parent can be enabled and whose conditions can hold, until nothing changes.
Whether one condition can hold follows the preview's
evaluateCondition: an unanswered question only satisfiesexistswithfalse, a comparison with an answer type the question cannot have only satisfies!=, and ordering operators need an ordered answer type.Any enabled question with the referenced linkId can answer, as in the preview, which keeps answers by linkId.
Cycles without initial answers and conditions on an item's own descendants therefore come out as never shown, and so does everything inside a group that is never shown.
Conditions that can each hold but contradict each other, such as
q = 1andq = 2withall, are not detected; the README says so.The rows form an ARIA tree that is the textual equivalent of the graph, and the SVG is hidden from assistive technology.
Item rows are level 1 and deeper by nesting, conditions are one level below their item, and the summary is the tree's description.
Each row has an explicit label, such as "Choice, Do you smoke?, linkId smoke, 4 conditions depend on it" or "when contact is answered, Refers to a later item".
↑ and ↓ move through the rows, Home and End go to the first and last row, ← goes to the item or group a row belongs to, → goes into it, and Enter on a condition moves to the question it refers to.
The panel tolerates imported values of the wrong type, such as a numeric
textor ananswerCodingthat is not an object.For the same reason, the preview's
isItemEnabledandinitialAnswersnow skipenableWhen,answerOptionandinitialvalues that are not arrays, and conditions and answer options that are not objects, since the flow reuses them.The flow follows the system light or dark appearance like the rest of the editor.
📚 Documentation
The
anvil-coreREADME describeslayoutFlowand its rows, edges, statuses and reachability.The
anvil-reactREADME lists the built-in side panel tabs and their ids and describes the Flow tab; its host panel example no longer uses a branching graph.The root README lists the flow view among the features.
✅ Testing
anvil-core/test/flow.test.tscovers row order and nesting depth in groups, conditions withallandany, answer formatting with option displays, themissing,later,selfandnot-a-questionstatuses, reachability with missing questions, chains,exists false, wrong answer types and ordering operators, groups, cycles and conditions on an item's own children, cycles that initial answers enable, repeated linkIds, lane assignment without overlaps and with shared trunks, and imported values of the wrong type.anvil-react/test/flowPanel.test.tsxcovers the tree's row labels, levels and description, edges with validation and later-item findings and the stub for a missing item, visible findings next to a status, imported values of the wrong type, selection from rows, from condition questions and from the store, keyboard navigation including Enter to the referenced question, updates after edits and an empty questionnaire, and checks that React logs no errors, which includes key warnings.Code of Conduct & Contributing Guidelines
By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: